#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <stdlib.h>


int main()
{

    printf("textexec ... begin!\n");
    pid_t id = fork();
    if(id == 0)
    {
        sleep(2);
        // child
       // execl("/usr/bin/ls", "ls", "-l", "-a", NULL);
       execlp("ls", "ls", "-l", "-a", NULL);
      // char* const argv[] = {"ls", "-l", "-a", NULL};
      // execvp("ls", argv);
       //execv("/usr/bin/ls", argv);
        exit(1); // 替换失败，子进程退出,退出码为1
    }
    // father
    int status = 0;
    pid_t rid = waitpid(id, &status, 0);
    if(rid > 0)
    {
        printf("father wait success, child exit code: %d\n", WEXITSTATUS(status));
    }
    printf("testexec ... end!\n");
  //  printf("textexec ... begin!\n");
  //  execl("/usr/bin/ls", "ls", "-a", "-l", NULL);
  //  printf("testexec ... end!\n");

    return 0;
}

